import { setToken, http, clearToken } from "@/utils"
export const login = (mobile, code) => {
  return async (dispatch) => {
    const res = await http.post("/authorizations", {
      mobile,
      code
    })
    // 注意：此处获取的是 token 不是 refresh_token
    const { token } = res.data.data
    dispatch({ type: "login/token", payload: token })
    setToken(token)
  }
}

export const logout = () => {
  return (dispatch, getState) => {
    // 1 清除 token
    dispatch({ type: "login/clearToken" })
    // 清除本地 token
    clearToken()
    // 2 清除个人信息
    dispatch({ type: "user/clearInfo" })
  }
}
